//package com.yilong.springcloudalibabanacos.sys.controller;
//
//import com.yilong.springcloudalibabanacos.sys.entity.SysDept;
//import lombok.extern.slf4j.Slf4j;
//import org.elasticsearch.action.index.IndexRequest;
//import org.elasticsearch.action.index.IndexResponse;
//import org.elasticsearch.action.support.WriteRequest;
//import org.elasticsearch.client.RequestOptions;
//import org.elasticsearch.client.RestHighLevelClient;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.messaging.Message;
//import org.springframework.messaging.support.MessageBuilder;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.io.IOException;
//import java.util.List;
//import java.util.UUID;
//import java.util.concurrent.ConcurrentHashMap;
//
///**
// * @ProjectName: springcloud-alibaba-yilong
// * @Package: com.yilong.springcloudalibabanacos.sys.controller
// * @ClassName: MqMessageController
// * @Author: WYL
// * @Description:
// * @Date: 2021/8/29 20:00
// * @Version: 1.0.0
// */
//
//@Slf4j
//@RestController
//@RequestMapping("/mq")
//public class MqMessageController {
//
//    @Autowired
//    private SysDeptController sysDeptController;
//
//    // @Autowired
//    // private RocketMQTemplate rocketMQTemplate;
//
//    @Autowired
//    RestHighLevelClient highLevelClient;
//
//    @RequestMapping("testElasticSearch")
//    public void testElasticSearch() throws IOException {
//        ConcurrentHashMap<String, Object> map = new ConcurrentHashMap(16);
//        map.put("feature", "high-level-rest-client");
//
//        IndexRequest request = new IndexRequest("spring-data")
//                .id(UUID.randomUUID().toString())
//                .source(map)
//               .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
//
//        IndexResponse response = highLevelClient.index(request, RequestOptions.DEFAULT);
//        System.out.println("response = " + response);
//    }
//
//    /**
//     * @return java.lang.String
//     * @throws
//     * @title sendSynMsg
//     * @description 发送同步消息
//     * @author WYL
//     * @updateTime 2021/9/4 13:11
//     */
//    @RequestMapping("/sendSynMsg")
//    public String sendSynMsg() {
//        sysDeptController.list().forEach(x -> {
//            Message<SysDept> build = MessageBuilder.withPayload(x).build();
//            String dest = String.format("%s:%s", "MY_TOPIC", "sendSynMsg");
//            // SendResult sendResult = rocketMQTemplate.syncSend(dest, build);
//            log.info("sendSynMsg ====>:{}", dest);
//        });
//        return "id";
//    }
//
//
//    /**************验证RocketMQ顺序消费***************/
//    @RequestMapping("/send/ordered")
//    public String sendOrderedMsg() {
//        /**
//         * hashKey: 为了保证报到同一个队列中，将消息发送到orderTopic主题上
//         */
//        List<SysDept> list = sysDeptController.list();
//        for (int i = 0; i < list.size(); i++) {
//            // rocketMQTemplate.syncSendOrderly("MY_TOPIC", i + JsonUtil.toStr(list.get(i)), "order");
//        }
//        return "success";
//    }
//
//}
